﻿@model ZdSoft.Model.User

@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Register</title>
    <link href="~/Content/layer.css" rel="stylesheet" />
    <link href="~/Content/layui.css" rel="stylesheet" />
    <style>
        .layui-container{
            margin-top:12px;
        }
        .layui-container .layui-col-md9{
            margin-top:8px;
        }
    </style>
</head>
<body>
    @using (Html.BeginForm()) 
    {
        @Html.AntiForgeryToken()

    <div class="layui-container">
        <h3 style="text-align:center;margin-top:10px">用户注册</h3>
        <hr />

        <div class="layui-container">
            @Html.LabelFor(model => model.Account, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="layui-col-md9">
                @Html.EditorFor(model => model.Account, new { htmlAttributes = new { @placeholder = "Account", @autocomplete = "off", @class = "layui-input" } })
                @Html.ValidationMessageFor(model => model.Account, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="layui-container">
            @Html.LabelFor(model => model.UserName, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="layui-col-md9">
                @Html.EditorFor(model => model.UserName, new { htmlAttributes = new { @placeholder = "UserName", @autocomplete = "off", @class = "layui-input" } })
                @Html.ValidationMessageFor(model => model.UserName, "", new { @class = "text-danger" })
            </div>
        </div>

        <div class="layui-container">
            @Html.LabelFor(model => model.Password, htmlAttributes: new { @class = "control-label col-md-2" })
            <div class="layui-col-md9">
                @Html.PasswordFor(model => model.Password, new { htmlAttributes = new { @placeholder = "Password", @autocomplete = "off", @class = "layui-input" } })
                @Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })
            </div>
        </div>
        <div class="layui-container">
            <div class="layui-col-md9">
                <input type="button" id="back" class="layui-btn" value="取消" />
                <input type="button" id="save" class="layui-btn" value="确认注册" />
            </div>
        </div>
    </div>
    }
    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Scripts/layer.js"></script>
    <script>
        $(function () {
            $("#Account").blur(function () {
                $.get("../User/UserIsExite", { account: $(this).val().trim() }, function (data) {
                    if (data.statu == true) {
                        layer.msg("该用户名已经存在，请换用其它账号");
                        return ;
                    }
                });
            });
            $("#back").click(function () {
                //parent.window.location = "http://localhost:24833/User/Login";
                parent.layer.closeAll();
            });
            $("#save").click(function () {
                $.get("../User/UserIsExite", { account: $(this).val().trim() }, function (data) {
                    if (data.statu == true) {
                        layer.msg("该用户名已经存在，请换用其它账号");
                        return;
                    }
                });
                var Account=$("#Account").val().trim();
                var UserName=$("#UserName").val().trim();
                var Password = $("#Password").val().trim();
                if (Account == "" || UserName == "" || Password == "")
                {
                    layer.alert("数据不能为空");
                    return;
                }
                var data={
                    account:Account,
                    username:UserName,
                    password:Password
                };
                $.post("../User/Register", data, function (data) {
                    if (data.statu == true)
                    {
                        //parent.window.location = "http://localhost:24833/User/Login";
                        layer.msg("注册成功", { time: 2000 }, function () {
                            parent.layer.closeAll();
                        });
                    }
                    else {
                        layer.alert(data.statu, {}, function () {
                            return;
                        });
                    }
                } );
            });
        });

    </script>
    
</body>
</html>
